package com.yunchang.springboot.scheduled.amazon.mws.report.datadispose;

import com.yunchang.springboot.models.Shop;
import com.yunchang.springboot.models.mwsreportbean.MwsReceiveInventory;
import com.yunchang.springboot.models.mwsreportbean.MwsReceiveInventoryDO;
import com.yunchang.springboot.scheduled.amazon.mws.report.datadispose.parent.ReportDataDisposeParent;
import com.yunchang.springboot.scheduled.amazon.mws.report.datadispose.reportinterface.IReportDataDispose;
import com.yunchang.springboot.utils.DateUtil;
import com.yunchang.springboot.utils.ToolUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author czw
 * @date 2020/7/28 0028  18:49
 * @description:
 */
@Component
public class ReceiveInventoryDataDispose extends ReportDataDisposeParent implements IReportDataDispose {
    /**
     * 已接收库存 将获取到的数据转为实体对象数组
     *
     * @param lists
     * @param shopBrandName
     * @param area
     * @return
     * @throws Exception
     */
    @Override
    public List<Object> reportDataDispose(List<List<String>> lists, String shopBrandName, String area,String sellerId) throws Exception {
        List<String> titleList = lists.get(0);
        Map<String, Object> titleMap = new HashMap<>(titleList.size());
        for (int i = 0; i < titleList.size(); i++) {
            titleMap.put(titleList.get(i), i);
        }
        int receivedDateIndex = Integer.valueOf(String.valueOf(titleMap.get("received-date")));
        int fnskuIndex = Integer.valueOf(String.valueOf(titleMap.get("fnsku")));
        int skuIndex = Integer.valueOf(String.valueOf(titleMap.get("sku")));
        int productNameIndex = Integer.valueOf(String.valueOf(titleMap.get("product-name")));
        int quantityIndex = Integer.valueOf(String.valueOf(titleMap.get("quantity")));
        int fbaShipmentIdIndex = Integer.valueOf(String.valueOf(titleMap.get("fba-shipment-id")));
        int fulfillmentCenterIdIndex = Integer.valueOf(String.valueOf(titleMap.get("fulfillment-center-id")));
        List<Object> insertList = new ArrayList<>(lists.size());
        for (int i = 1; i < lists.size(); i++) {
            MwsReceiveInventoryDO inventory = new MwsReceiveInventoryDO();
            List<String> row = lists.get(i);
            inventory.setSellerId(sellerId);
            inventory.setArea(area);
            inventory.setReceivedDate(DateUtil.ISO8601ToGMT(row.get(receivedDateIndex)));
            inventory.setFnsku(row.get(fnskuIndex));
            inventory.setSku(row.get(skuIndex));
            inventory.setProductName(row.get(productNameIndex));
            inventory.setQuantity(ToolUtil.valueOfInteger(row.get(quantityIndex)));
            inventory.setFbaShipmentId(row.get(fbaShipmentIdIndex));
            inventory.setFulfillmentCenterId(row.get(fulfillmentCenterIdIndex));
            inventory.setCreateTime(DateUtil.getDate());
            inventory.setUpdateTime(DateUtil.getDate());
            inventory.setFinanceStatus(1);
            insertList.add(inventory);
        }
        return insertList;
    }
}
